//
//  ZLPHAssetExtension.swift
//  ZLExtension
//
//  Created by 科大 on 2024/12/23.
//

import Photos

public extension PHAsset {
    func zl_requestImage(size: CGSize = CGSizeZero, completion: @escaping (_ image: UIImage?) -> Void) {
        var targetSize = size
        if targetSize == CGSizeZero {
            targetSize = CGSizeMake(CGFloat(self.pixelWidth), CGFloat(self.pixelHeight))
        }
        let imageManager = PHImageManager.default()
        let requestOptions = PHImageRequestOptions()
        requestOptions.isSynchronous = true
        requestOptions.resizeMode = .exact
        imageManager.requestImage(for: self, targetSize: size, contentMode: .aspectFill, options: requestOptions) { (image, info) in
            completion(image)
        }
    }
    
    class func zl_saveImagesToLocal(assets: [PHAsset], path: String, completion: @escaping (_ success: Bool, _ error: Error?) -> Void) {
//        PHPhotoLibrary.shared().performChanges({
//            PHAssetChangeRequest.creationRequestForAsset(from: image)
//        }) { (success, error) in
//            completion(success, error)
//        }
    }
}
